package com.ming.mapper;

import com.ming.annotation.AutoFill;
import com.ming.dto.EmployeePageQueryDTO;
import com.ming.entity.Employee;
import com.github.pagehelper.Page;
import com.ming.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface EmployeeMapper {
    /**
     * 根据用户名查询员工
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 根据ID查询员工
     */
    @Select("select * from employee where id = #{id}")
    Employee getById(Long id);

    /**
     * 插入员工数据
     */
    @Insert("insert into employee (username, name, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user) " +
            "values (#{username}, #{name}, #{password}, #{phone}, #{sex}, #{idNumber}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @AutoFill(value = OperationType.INSERT)
    void insert(Employee employee);

    /**
     * 员工分页查询
     * @param employeePageQueryDTO
     * @return
     */
    Page<Employee> pageQuery(EmployeePageQueryDTO employeePageQueryDTO);

    /**
     * 根据主键动态修改员工信息
     * @param employee
     */
    @Update("update employee set " +
            "status = #{status}, " +
            "update_time = #{updateTime}, " +
            "update_user = #{updateUser} " +
            "where id = #{id}")
    @AutoFill(value = OperationType.UPDATE)
    void update(Employee employee);

    /**
     * 根据主键动态修改员工基本信息
     * @param employee
     */
    @AutoFill(value = OperationType.UPDATE)
    void updateInfo(Employee employee);
}